<?php

namespace app\common\controller;

use cmf\controller\AdminBaseController;

class AppBaseController extends AdminBaseController
{
    public function updateStatus($url = 'index')
    {
        $params = input('param.');

        $id = isset($params['update_id']) ? $params['update_id'] : 0;
        unset($params['update_id']);
        $status = isset($params['update_status']) ? $params['update_status'] : 0;
        unset($params['update_status']);

        $model = model($this->request->controller());

        $where['id'] = $id;
        $channel     = $model->where($where)->find();
        if ($channel) {
            $update = $model->update(['status' => $status], $where);
            if ($update) {
                $this->success('操作成功', url($url, $params));
            } else {
                $this->error('操作失败');
            }
        } else {
            $this->error('数据不存在');
        }
    }

    public function delete($url = 'index')
    {
        $params = input('param.');

        $id = isset($params['delete_id']) ? $params['delete_id'] : 0;
        unset($params['delete_id']);
        $model = model($this->request->controller());

        $where['id'] = $id;
        $delete      = $model->where($where)->delete();
        if ($delete) {
            $this->success('删除成功', url($url, $params));
        } else {
            $this->error('删除失败');
        }
    }
}
